<template>
  <div>
    <div class="form_wrap">
      <el-form label-width="150px" style="margin-top: 10px">
        <el-row>
          <el-col :span="2"> 财务信息: </el-col>
          <el-row>
            <el-col :xl="6" :lg="7">
              <el-form-item class="posInput ts" label="收费金额:">
                <el-input
                  v-model="cw.chargeMoney"
                  :disabled="true"
                  @input="this.$forceUpdate()"
                ></el-input>
                <span class="pos right">（元）</span>
              </el-form-item>
            </el-col>
            <el-col :xl="6" :lg="7">
              <el-form-item label="实际收费时间:">
                <el-date-picker
                  v-model="cw.chargeTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                  @input="this.$forceUpdate()"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :xl="2" :lg="3" style="line-height: 20px">
              <el-button
                @click="openDiaCharge"
                v-if="showChargeBtn && (orderStatus == 3 || orderStatus == 4)"
                >{{ chargeTitle }}</el-button
              >
            </el-col>
          </el-row>
        </el-row>
      </el-form>
    </div>
    <!--弹框-->
    <el-dialog
      title="修改信息"
      :visible.sync="dialogTableVisible"
      v-if="dialogTableVisible"
    >
      <el-form label-width="150px" v-if="showdis == 2" :model="diacw">
        <el-row>
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="收费金额:"
              prop="chargeMoney"
            >
              <el-input v-model="diacw.chargeMoney"></el-input>
              <span class="pos right ht-right">（元）</span>
            </el-form-item></el-col
          >
          <el-col :span="12"
            ><el-form-item label="选择实际收费时间:" prop="chargeTime">
              <el-date-picker
                v-model="diacw.chargeTime"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker> </el-form-item
          ></el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitcharge">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  getUpForm,
  postChargeAccs,
  getProductUrl,
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
import { GMTToStr } from "../../assets/js/utlis";
export default {
  name: "LoanInfor",
  props: ["orderNumber"],
  data() {
    return {
      dialogTableVisible: false,
      orderStatus: null,
      //财务
      cw: {
        chargeMoney: null,
        chargeInvoiceTime: null,
        chargeTime: null,
        calculateRatio: null,
        calculateAddMoney: null,
      },
      diacw: {},
      chargeTitle: "修改",
      showdis: null,
      diaTitle: null,
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      golbalPermissions: [],
      ProductUrl: "",
    };
  },
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.status = eval(this.$route.query.status);
    if (!this.status) {
      this.getUpForm(this.orderNumber);
    }
    this.findProductUrl(this.orderNumber);
  },
  computed: {
    //财务信息添加按钮
    showChargeBtn: function () {
      return checkPermiss("business:fund:change", this.golbalPermissions);
    },
  },
  methods: {
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber,
      }).then((res) => {
        this.ProductUrl = res.data.productUrl;
        this.orderStatus = res.data.orderStatus;
      });
    },
    //根据订单号查询当前信息
    getUpForm(orderNumber) {
      let that = this;
      getUpForm({
        orderNumber: orderNumber,
      }).then((res) => {
        let data = res.data;
        that.cw.chargeMoney = data.chargeMoney;
        that.cw.chargeTime = data.chargeTime;
        if (that.cw.chargeMoney == null) {
          that.chargeTitle = "添加数据";
        }
      });
    },
    openDiaCharge() {
      this.showdis = 2;
      this.dialogTableVisible = true;
      this.diacw = JSON.parse(JSON.stringify(this.cw));
    },
    //财务提价按钮
    submitcharge() {
      this.diacw.orderNumber = this.orderNumber;
      if (this.diacw.chargeTime) {
        this.diacw.chargeTime = GMTToStr(this.diacw.chargeTime);
      }
      postChargeAccs(this.diacw).then((res) => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.chargeTitle = "修改";
          this.dialogTableVisible = false;
          this.$message.success(res.message);
          //this.$router.push({ path: this.ProductUrl });
        }
      });
    },
  },
};
</script>

<style scoped type="less">
.posInput
{
    position: relative;
}
.pos
{
    position: absolute;  z-index: 2;
}
.pos.left
{
    left: 10px;
}
.pos.right
{
    right: 0;
}
.posInput ::v-deep .el-input__inner
{
    padding: 0 50px 0 40px;  text-align: center;
}
.posInput.ts ::v-deep .el-input__inner
{
    padding-left: 25px;
}
.toBe
{
    line-height: 35px;
}
.form_wrap ::v-deep .el-form-item,
.form_wrap ::v-deep .el-form-item__label,
.form_wrap ::v-deep .el-form-item__content,
.form_wrap ::v-deep .el-input,
.form_wrap ::v-deep .el-input__inner
{
    line-height: 32px;  height: 32px;
}
.form_wrap ::v-deep .el-form-item
{
    margin-bottom: 5px;
}
.form_wrap ::v-deep .el-col
{
    line-height: 32px;
}
.form_wrap ::v-deep .el-button
{
    padding: 8px 20px;
}
.form_wrap ::v-deep.el-input__icon
{
    line-height: 24px;
}
::v-deep .el-form-item__content
{
    text-align: left;
}
.el-date-editor.el-input
{
    width: auto;
}

</style>
